package com.aiatomic.couting.widgets;

import com.aiatomic.couting.R;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.KeyEvent;
import android.widget.TextView;

public class LoadingDialog extends Dialog {
	private TextView tv_text;
	private LoadingView loadingview;

	public LoadingDialog(Context context) {
		super(context);
		/** 设置对话框背景透明 */
		getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
		setContentView(R.layout.loading);
		loadingview = (LoadingView) findViewById(R.id.loadingview);
		loadingview.start();// 开始动画
		tv_text = (TextView) findViewById(R.id.tv_text);
		setCanceledOnTouchOutside(false);
		this.setCancelable(false);
		this.setOnKeyListener(new DialogInterface.OnKeyListener() {
			@Override

			public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event)

			{
				if (KeyEvent.KEYCODE_BACK == keyCode) {
					return false;
				}
				return false;
			}

		});
	}

	/**
	 * 为加载进度个对话框设置不同的提示消息
	 *
	 * @param message
	 *            给用户展示的提示信息
	 * @return build模式设计，可以链式调用
	 */
	public LoadingDialog setMessage(String message) {
		tv_text.setText(message);
		return this;
	}
}